package com.zzk.lanouhn.myapplication1.activity;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ImageView;

import com.zzk.lanouhn.myapplication1.R;

/**
 * Created by lanouhn on 16/9/1.
 */
public class RankDetailsActivity extends AppCompatActivity {

    private WebView web;
    private String webUrl;
    private ImageView iv_back;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_rankdetails);
        initView();
        initData();
        initEvent();
    }

    private void initView() {
        web = (WebView) findViewById(R.id.web_rank_details);
        iv_back = (ImageView) findViewById(R.id.iv_back_rank);
    }

    private void initData() {
        Bundle bundle = this.getIntent().getExtras();
        webUrl = bundle.getString("排行榜");
    }

    private void initEvent() {
        WebSettings webSettings = web.getSettings();
        webSettings.setPluginState(WebSettings.PluginState.ON);
        webSettings.setUseWideViewPort(true);
        webSettings.setJavaScriptEnabled(true);
        web.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
//        webview.loadUrl(url);
        //WebView加载web资源
        web.loadUrl(webUrl);
        //覆盖WebView默认使用第三方或系统默认浏览器打开网页的行为，使网页用WebView打开
        web.setWebViewClient(new WebViewClient() {
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                // TODO Auto-generated method stub
                //返回值是true的时候控制去WebView打开，为false调用系统浏览器或第三方浏览器
                view.loadUrl(url);
                return true;
            }
        });
        iv_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }
}
